package org.jfsm.core;

final class Dispatcher {
    private final int eidOffset;
    FSMWorker worker;

    Dispatcher(int eidOffset) {
        this.eidOffset = eidOffset;
    }

    void dispatch(FSMContext ctx, int eid, Object msg) {
        InstanceState context = (InstanceState) ctx;

        worker.logger.submitting(context, eidOffset + eid, msg);
        worker.submit(context, eidOffset + eid, msg);
    }

    void initContext(FSMContext ctx) {
        ((InstanceState) ctx).setStateID(worker.initStateID);
    }

    // For Caching work (implementation is incomplete)
    Object createWork(int eid, Object msg) {
        return worker.createWork(eid, msg);
    }

    void dispatch(FSMContext ctx, Object work) {
        worker.submit((InstanceState) ctx, work);
    }
}